import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Copy {
    public static void main(String[] args) throws IOException {
        FileReader fileReader = null;
        FileWriter fileWriter = null;
        try {
            fileReader = new FileReader("D:\\Copy\\characterStream\\farrago.txt");
            fileWriter = new FileWriter("D:\\Copy\\characterStream\\outAgain.txt");

            int c;
            while((c = fileReader.read()) != -1){
                fileWriter.write(c);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            fileReader.close();
            fileWriter.close();
        }
        System.out.println("原文件内容：");
        printFileContent("D:\\Copy\\characterStream\\farrago.txt");
        System.out.println("复制后文件内容：");
        printFileContent("D:\\Copy\\characterStream\\outAgain.txt");
    }
    private static void printFileContent(String filename) {
        try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}